package com.neuedu.his.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neuedu.his.po.Settlecategory;
import com.neuedu.his.service.SettlecategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/master/settle")
public class SettleClassController {

    @Autowired
    private SettlecategoryService service;

    /** 1. 列表（只要 DelMark=1） */
    @GetMapping("/list")
    public List<Settlecategory> list() {
        LambdaQueryWrapper<Settlecategory> qw = new LambdaQueryWrapper<Settlecategory>()
                .eq(Settlecategory::getDelmark, 1)
                .orderByAsc(Settlecategory::getSequenceno);
        return service.list(qw);
    }

    /** 2. 按 ID 查询（编辑前拉最新） */
    @GetMapping("/getById/{id}")
    public Settlecategory getById(@PathVariable Integer id) {
        return service.getById(id);
    }

    /** 3. 新增或修改 */
    @PostMapping("/saveOrUpdate")
    public boolean saveOrUpdate(@RequestBody Settlecategory item) {
        // MyBatis-Plus 根据 id 是否为空决定 insert / update
        return service.saveOrUpdate(item);
    }

    /** 4. 物理删除 */
    @DeleteMapping("/deleteById/{id}")
    public boolean deleteById(@PathVariable Integer id) {
        return service.removeById(id);
    }
}
